package com.demo.service;

import com.alibaba.fastjson.JSONObject;
import com.demo.Pojo.Books;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 处理需要降级的服务 需要实现：FallbackFactory
 */
@Component
public class FeignBookServiceFallFactory implements FallbackFactory {

    @Override
    public Object create(Throwable throwable) {
        return new FeignBookServiceFall() {
            @Override
            public Books queryById(int id) {
                Books books = new Books();
                books.setBookName("msg=====>进行了服务降级处理，关闭了此服务");
                return books;
            }

            @Override
            public JSONObject queryAll() {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("msg==>","进行了服务降级处理，关闭了此服务");
                return jsonObject;
            }
        };
    }
}
